package org.celery.modules.other.service.impl;

import org.celery.modules.other.entity.SevenElevenShop;
import org.celery.modules.other.excel.SevenElevenShopExcel;
import org.celery.modules.other.vo.SevenElevenShopVO;
import org.celery.modules.other.mapper.SevenElevenShopMapper;
import org.celery.modules.other.service.ISevenElevenShopService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 7-11商超表 服务实现类
 *
 * @author Celery
 * @since 2022-06-08
 */
@Service
public class SevenElevenShopServiceImpl extends BaseServiceImpl<SevenElevenShopMapper, SevenElevenShop> implements ISevenElevenShopService {

	@Override
	public IPage<SevenElevenShopVO> selectSevenElevenShopPage(IPage<SevenElevenShopVO> page, SevenElevenShopVO sevenElevenShop) {
		return page.setRecords(baseMapper.selectSevenElevenShopPage(page, sevenElevenShop));
	}

	@Override
	public void importData(List<SevenElevenShopExcel> list) {
		List<SevenElevenShop> sevenElevenShopList = list();
		list.forEach(dataExcel -> {
			SevenElevenShop sevenElevenShop = Objects.requireNonNull(BeanUtil.copy(dataExcel, SevenElevenShop.class));
			for (SevenElevenShop item : sevenElevenShopList) {
				if (item.getSerial().equals(dataExcel.getSerial())) {
					sevenElevenShop.setId(item.getId());
					break;
				}
			}
			this.saveOrUpdate(sevenElevenShop);
		});
	}

}
